package sensornetwork;

import snifc.PacketIfc;

public class Packet implements PacketIfc{
	
	private int idPacket;
	private int ttl;
	private int idSource;
	
	public Packet(int idSource, int idPacket, int ttl){
		this.idSource = idSource;
		this.idPacket = idPacket;
		this.ttl=ttl;
	}
	
	public boolean isTimeToLiveOK(){
    boolean stillAlive;
		if (this.ttl > 0){
			stillAlive = true;
		}
		else {
			stillAlive = false;
		}
		return stillAlive;
	}
			
	public String toString(){
		return ("Le paquet "+this.idPacket+ " a pour source  "+this.idSource);
	}
	

	public int getId(){
		return (this.idPacket);
	}

	public int compareTo(Object o){
		Packet p=(Packet)o;
		return (new Integer(this.idPacket).compareTo(new Integer(p.getId())));		
	}	
  
  public void ttlDecrement () {
    this.ttl--;
  }	
}
